package com.takeaway.presenter

import android.util.Log
import com.takeaway.model.beans.Order
import com.takeaway.model.net.ResponseInfo
import com.takeaway.ui.fragment.OrderFragment
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import rx.Observable
import rx.schedulers.Schedulers

class OrderFragmentPresenter(val orderFragment: OrderFragment): NetPresenter() {
    override fun errorCallBack() {

    }

    fun getOrderList(userId: String) {
//        val order = takeoutService.getOrderList("1")
//        order.enqueue(callBack)

        // 利用rxjava处理
//        val obserable = takeoutService.getOrderListByRxJava("1")
//        obserable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread() as rx.Scheduler).subscribe(object: Observer<ResponseInfo> {
//            override fun onComplete() {
//
//            }
//
//            override fun onError(e: Throwable) {
//
//            }
//
//            override fun onNext(t: ResponseInfo) {
//
//            }
//        })


        var dataList = ArrayList<Order>()
        for (index in 0 until 15) {
            val order = Order()
            order.name = "测试" + index
            order.type = "类型" + index
            dataList.add(order)
        }

        orderFragment.OnSuccess(dataList)
    }

    override fun parserJson(data: String) {
        // 解析成 List<Order>

        Log.e("ss", "sss")
    }
}